package org.example.heap;

import java.io.FileWriter;
import java.io.IOException;

/**
 * 生成一个文件，这个文件中包含10万个长度不超过 10的字符串
 * @author youshang
 * @date 2022/03/27 11:51
 **/
public class GenerateString {

    public static void main(String[] args) throws IOException {
        FileWriter fileWriter = new FileWriter("word.txt");
        for (int i = 0; i < 100000; i++) {
            int length = (int) (Math.random() * 10 + 1);
            fileWriter.write(getString(length) + "\n");
        }
        fileWriter.close();
    }

    private static String getString(int length){
        String str = "";
        for (int i = 0; i < length; i++) {
            int num = (int) (Math.random() * (96 - 65 + 1) + 65) + (int) (Math.random() * 2 + 32);
            str += (char)num;
        }
        return str;
    }
}
